//
//  HTSpecialOfferForYou.swift
//  MagaCore
//
//  Created by 罗林轩 on 2024/8/29.
//  Copyright © 2024 HT. All rights reserved.
//

import SwiftUI

// MARK: - SpecialOfferForYou显示

struct HTSpecialOfferForYou: View {
    @State var price: String = ""
    var body: some View {
        ZStack {
            Image("会员引导底图")
                .resizable() // 使图片可调整大小
                .aspectRatio(contentMode: .fill) // 填充视图区域
            VStack(alignment: .leading, spacing: 5) {
                Text("Special Offer For You")
                    .ht_commonTextStyle(color: Color(hex: "#222222"), fontSize: 15, weight: .bold)
                HStack(alignment: .bottom) {
                    Text(price)
                        .ht_commonTextStyle(color: Color(hex: "#222222"), fontSize: 18, weight: .bold)
                    Text("for the one month")
                        .ht_commonTextStyle(color: Color(hex: "#222222"), fontSize: 14, weight: .regular)
                    Spacer()
                }
            }
            .padding(.leading, 20)
        }
        .onTapGesture {
            /** 发送通知修改tab */
            NotificationCenter.default.post(name: HTConfig.STATIC_notification_changeTabbar, object: nil, userInfo: ["currentIndex": 3])
        }
        .onAppear {
            // MARK: - 调用326接口
            HTNetworkManager().ht_request(.htEnumSubscribeRestore(var_pid: "", var_receipt: "")) { result in
                if result.var_status == "200" {
                    let var_data = result.ht_dataDist()!
                    let server_k6 = (var_data["server"] as? [String: Any])?["k6"] as? Int ?? 0
                    let device_k6 = (var_data["device"] as? [String: Any])?["k6"] as? Int ?? 0
                    if server_k6 == 0 && device_k6 == 0 {
                        price = "$2.99"
                    } else {
                        price = "$4.99"
                    }
                }
            }
        }
        .padding(.horizontal, 20)
        .frame(width: var_screenWidth, height: 60)
    }
}

#Preview {
    HTSpecialOfferForYou()
}
